#转换mask为灰度值

# import os,re
# from PIL import Image
# import numpy as np
# import pandas as pd
# import cv2
# import matplotlib.pyplot as plt
#
# def atoi(text) :
#     return int(text) if text.isdigit() else text
# def natural_keys(text) :
#     return [atoi(c) for c in re.split('(\d+)', text)]
#
# # read_csv = pd.read_csv("D:/deepglobe2/class_dict.csv",index_col=False,skipinitialspace=True)
# # print(read_csv)
#
#
# def segmantation_images(path, new_path, debug_test_num):
#     filenames = []
#
#     for root, dirnames, filenames in os.walk(path):
#         filenames.sort(key=natural_keys)
#         rootpath = root
#
#     # print(filenames)
#     count = 0
#     for item in filenames:
#
#         if debug_test_num != 0:
#             if debug_test_num <= count:
#                 break
#
#         count = count + 1
#
#         if os.path.isfile(path + item):
#             f, e = os.path.splitext(item)
#             image_rgb = Image.open(path + item)
#             image_rgb = np.asarray(image_rgb)
#             new_image = np.zeros((image_rgb.shape[0], image_rgb.shape[1], 3)).astype('int')
#
#             for index, row in read_csv.iterrows():
#                 new_image[(image_rgb[:, :, 0] == row.r) &
#                           (image_rgb[:, :, 1] == row.g) &
#                           (image_rgb[:, :, 2] == row.b)] = np.array([index , index , index ]).reshape(1, 3)
#
#             # # ...
#             # for index, row in read_csv.iterrows():
#             #     new_image[(image_rgb[:, :, 0] == row.r) &
#             #               (image_rgb[:, :, 1] == row.g) &
#             #               (image_rgb[:, :, 2] == row.b)] = index  # 直接使用index而不是index + 1
#             # # ...
#
#
#
#             new_image = new_image[:, :, 0]
#             output_filename = new_path + f + '.png'
#             cv2.imwrite(output_filename, new_image)
#             print('writing file: ', output_filename)
#
#         else:
#             print('no file')
#
#     print("number of files written: ", count)
#
# #
# debug_test_num = 0 # 5 samples are enough just to see it working. If you set 0, you can do all the datasets.
# segmantation_images("D:/deepglobe2/deep/masks/test/", "D:/deepglobe2/deep/mask2/test/", debug_test_num=debug_test_num)
#



#路径

# mask_files = os.listdir('/home/songst/0songst_file/deepglobe/masks/val/')
# image_sourcePath = '/home/songst/0songst_file/deepglobe/images/val/'
# mask_sourcePath = '/home/songst/0songst_file/deepglobe/masks/val/'
# image_savePath = '/home/songst/0songst_file/deepglobe/images/train_crop/'
# mask_savePath = '/home/songst/0songst_file/deepglobe/masks/train_crop/'

#
# mask_files = os.listdir("D:/deepglobe/mask2b/train/")
# image_sourcePath ="D:/deepglobe/images/train/"
# mask_sourcePath ="D:/deepglobe/masks/train/"
# image_savePath = "D:/deepglobe/images/train_612/"
# mask_savePath = "D:/deepglobe/mask2b/train_612/"
# #



#读取文件夹中的像素值
#
# import os
# import numpy as np
# from PIL import Image
#
# def get_unique_values_from_images(folder_path):
#     all_unique_values = set()
#
#     # 遍历文件夹中的所有文件
#     i=1
#     for filename in os.listdir(folder_path):
#         if filename.endswith(('.png', '.jpg', '.jpeg', ".tif")):
#             image_path = os.path.join(folder_path, filename)
#             image = Image.open(image_path)
#
#             # 将图像转换为numpy数组并获取唯一值
#             image_array = np.array(image)
#             unique_values = np.unique(image_array)
#
#             # 更新全局唯一值集合
#             all_unique_values.update(unique_values)
#         print("{} done ,no.{}".format(filename,i))
#         i=i+1
#     return all_unique_values
# #
# folder_path = "C:/Users/SONGSHITAO/Desktop/(aeril77)/isdnet-v4.5 (copy)/aeril_result/77.19/"
# unique_pixel_values = get_unique_values_from_images(folder_path)
#
# print("Unique pixel values across all images:", sorted(list(unique_pixel_values)))
# #


##读取文件中的像素值

# import numpy as np
# from PIL import Image
# #
# # 打开图像
#
# image_path = "C:/Users/SONGSHITAO/Desktop/(aeril77)/isdnet-v4.5 (copy)/aeril_result/77.19/austin3.tif"
# image = Image.open(image_path)
# # 将图像转换为numpy数组
# image_array = np.array(image)


# 使用np.unique获取所有独特像素值
# unique_values = np.unique(image_array)
# print("Unique pixel values in the image:", unique_values)




#
# import cv2
# from PIL import Image
# import numpy as np
#
# # 读取多通道mask图像
# mask_sourcePath = "C:/Users/SONGSHITAO/Desktop/(aeril77)/isdnet-v4.5 (copy)/aeril_result/77.19/austin3.tif"
# mask_image = Image.open(mask_sourcePath)
# mat =np.array(mask_image)
# mask_img = cv2.imread(mask_sourcePath)
# matcv =np.array(mask_img)
#
#
#
# print(mat.shape,matcv.shape)




#
#
# #更改后缀
# import os
#
# def rename_files_in_directory(directory_path, old_suffix, new_suffix):
#     # 获取目录中的所有文件
#     filenames = os.listdir(directory_path)
#
#     # 遍历每个文件名，查找匹配的文件后缀
#     for filename in filenames:
#         if filename.endswith(old_suffix):
#             # 替换后缀并重命名文件
#             new_filename = filename.replace(old_suffix, new_suffix)
#             os.rename(
#                 os.path.join(directory_path, filename),
#                 os.path.join(directory_path, new_filename)
#             )
#
#     print("Renaming completed!")
#
# # 使用上述函数
# directory_path = "D:/deepglobe2/deep/mask2/val/"  # 将此路径更改为你的文件夹路径
# old_suffix = '_mask.png'
# new_suffix = '_sat.png'
# rename_files_in_directory(directory_path, old_suffix, new_suffix)



#resize原图
#
# def resize_dataset(image_dir, mask_dir, output_image_dir, output_mask_dir, new_size, num_classes):
#     # 创建输出目录
#     if not os.path.exists(output_image_dir):
#         os.makedirs(output_image_dir)
#     if not os.path.exists(output_mask_dir):
#         os.makedirs(output_mask_dir)
#
#     # 获取所有的图片文件名
#     image_filenames = os.listdir(image_dir)
#
#     i=1
#     for image_name in image_filenames:
#         # 对于每张图片，加载图片和对应的mask
#         image_path = os.path.join(image_dir, image_name)
#         mask_path = os.path.join(mask_dir, os.path.splitext(image_name)[0]+".png")
#
#         image = Image.open(image_path)
#         mask = Image.open(mask_path)
#
#         # resize图片和mask
#         image_resized = image.resize(new_size, Image.BILINEAR)
#         mask_resized = mask.resize(new_size, Image.NEAREST)
#
#         # 验证mask像素值确保在[0, num_classes-1]之间
#         for value in mask_resized.getdata():
#             assert 0 <= value < num_classes, "Unexpected pixel value in mask."
#
#         # 保存resize后的图片和mask
#         image_resized.save(os.path.join(output_image_dir, os.path.splitext(image_name)[0]+"rs"+".jpg"))
#         mask_resized.save(os.path.join(output_mask_dir, os.path.splitext(image_name)[0]+"rs"+".png"))
#         print("{} is done ,no.{}".format(image_name,i))
#         i+=1
#     print("Resizing completed!")
#
#
#
# # 调用上面定义的函数
# image_dir = "D:/deepglobe2/deep/images/train/"
# mask_dir = "D:/deepglobe2/deep/mask2/train/"
# output_image_dir = "D:/deepglobe2/deep/images/train_re1224/"
# output_mask_dir = "D:/deepglobe2/deep/mask2/train_re1224/"
# new_size = (1224,1224)  # 修改为所需的尺寸
# num_classes = 7  # 根据你的情况修改

# resize_dataset(image_dir, mask_dir, output_image_dir, output_mask_dir, new_size, num_classes)


#crop原图

# from PIL import Image
#
# mask_files = os.listdir("D:/deepglobe/masks/train2/")
#
# image_sourcePath ="D:/deepglobe/images/train/"
# mask_sourcePath ="D:/deepglobe/masks/train2/"
#
# image_savePath = "D:/deepglobe/images/train1224/"
# mask_savePath = "D:/deepglobe/masks/train1224/"
#
#
# if not os.path.exists(image_savePath):
#         os.makedirs(image_savePath)
# if not os.path.exists(mask_savePath):
#         os.makedirs(mask_savePath)
#
#
# def crop():
#     crop_size = 1224
#     i=0
#     for file in mask_files:
#         mask_img = Image.open(mask_sourcePath + file)
#         img = Image.open(image_sourcePath + os.path.splitext(file)[0] + ".jpg")
#
#         h, w = mask_img.size
#         step = 1224 // 4
#
#         for col in range(0, h - crop_size + 1, step):
#             for row in range(0, w - crop_size + 1, step):
#                 box = (row, col, row + crop_size, col + crop_size)
#
#                 sub_mask = mask_img.crop(box)
#                 sub_image = img.crop(box)
#
#                 image_name = image_savePath + file[:-8] + '-%d-%d' % (col, row) + '_sat.jpg'
#                 mask_name = mask_savePath + file[:-8] + '-%d-%d' % (col, row) + '_sat.png'
#
#                 sub_image.save(image_name)
#                 sub_mask.save(mask_name)
#         i+=1
#         print("{} is done,No.{}".format(file,i))
#
# crop()


# def crop():
#     crop_size = 1224
#     for file in mask_files:
#
#         # for times in range(1):
#
#             mask_img = Image.imread(mask_sourcePath + file)
#             img = Image.imread(image_sourcePath + os.path.splitext(file)[0]+".jpg")
#
#             h, w, _ = mask_img.shape
#             for item in range(1):
#                 # sz = random.randint(s, 2000)
#                 # half_sz = int(sz*0.8)
#                 step = 1224//2
#
#                 for col in range(0, h-crop_size+1, step):
#
#                     for row in range(0, w-crop_size+1, step):
#
#                         sub_mask = mask_img[col:col+crop_size, row:row+crop_size, :]
#                         sub_image = img[col:col+crop_size, row:row+crop_size, :]
#
#                         image_name = image_savePath + file[:-8] + '-%d-%d'%(col, row) +'_sat.jpg'
#                         mask_name = mask_savePath + file[:-8] + '-%d-%d'%(col, row) +'_sat.png'
#
#                         Image.imwrite(image_name, sub_image)
#                         Image.imwrite(mask_name, sub_mask)
#
#             print("{} is done.".format(file))

# crop()




# ##################################################################
#
# import os
# import shutil
#
# # 指定数据文件夹路径
# data_dir = "D:/deepglobe2/oringinal/train/"
#
# # 读取train.txt、val.txt和test.txt文件中的图像名称
# def load_image_names(txt_filename):
#     with open(txt_filename, 'r') as file:
#         image_names = file.read().splitlines()
#
#     return image_names
#
# train_image_names = load_image_names('D:/deepglobe2/oringinal/train.txt')
# val_image_names = load_image_names('D:/deepglobe2/oringinal/crossvali.txt')
# test_image_names = load_image_names('D:/deepglobe2/oringinal/test.txt')
#
# # 创建目标文件夹用于存储分配后的图像和掩模
# target_dir = "D:/deepglobe2/deep/"
#
# train_dir = os.path.join(target_dir, "im" ,'train')
# train_dirm = os.path.join(target_dir, "ma",'train')
#
# val_dir = os.path.join(target_dir, "im",'val')
# val_dirm = os.path.join(target_dir, "ma",'val')
#
# test_dir = os.path.join(target_dir, "im",'test')
# test_dirm = os.path.join(target_dir, "ma",'test')
#
#
# # 创建目标文件夹
# os.makedirs(train_dir, exist_ok=True)
# os.makedirs(val_dir, exist_ok=True)
# os.makedirs(test_dir, exist_ok=True)
# os.makedirs(train_dirm, exist_ok=True)
# os.makedirs(val_dirm, exist_ok=True)
# os.makedirs(test_dirm, exist_ok=True)
#
# # 复制图像和掩模到对应文件夹
# for image_name in train_image_names:
#     image_path = os.path.join(data_dir, 'images', image_name)
#     mask_path = os.path.join(data_dir, 'masks', image_name[:-8] + '_mask.png')
#     shutil.copy(image_path, os.path.join(train_dir, image_name))
#     shutil.copy(mask_path, os.path.join(train_dirm, image_name[:-8] + '_mask.png'))
#
# for image_name in val_image_names:
#     image_path = os.path.join(data_dir, 'images', image_name)
#     mask_path = os.path.join(data_dir, 'masks', image_name[:-8] + '_mask.png')
#     shutil.copy(image_path, os.path.join(val_dir, image_name))
#     shutil.copy(mask_path, os.path.join(val_dirm, image_name[:-8] + '_mask.png'))
#
# for image_name in test_image_names:
#     image_path = os.path.join(data_dir, 'images', image_name)
#     mask_path = os.path.join(data_dir, 'masks', image_name[:-8] + '_mask.png')
#     shutil.copy(image_path, os.path.join(test_dir, image_name))
#     shutil.copy(mask_path, os.path.join(test_dirm, image_name[:-8] + '_mask.png'))


#####################################################################################
#
# import matplotlib.pyplot as plt
#
# # 从文本文件读取数据
# with open("C:/Users/SONGSHITAO/Desktop/paper/论文图片/a.txt", "r") as file:
#     lines = file.readlines()
#
# # 提取网络名、精度和速度数据，使用空格分隔
# model_names = lines[0].strip().split()
# accuracies = [float(x) for x in lines[1].strip().split()]
# speeds = [float(x) for x in lines[2].strip().split()]
#
# # 创建散点图，增加图的尺寸
# plt.figure(figsize=(2,2))
#
# # 选择最后一个散点用不同颜色和标记表示
# highlight_index = len(model_names) - 1
#
# # 添加标签和颜色，同时记录标签和颜色的对应关系
# label_color_mapping = {}
# for i in range(len(model_names)):
#     label = model_names[i]
#     color = 'r' if i == highlight_index else 'g'
#     marker = '*' if i == highlight_index else 'o'
#     plt.scatter(speeds[i], accuracies[i], c=color, marker=marker, s=100, label=label)
#
#     # 更改点附近文字的颜色，同时增加字体大小
#     if i == highlight_index:
#         text_color = 'red'
#     else:
#         text_color = 'green'
#
#     plt.annotate(label, (speeds[i], accuracies[i]), textcoords="offset points", xytext=(0, 9), ha='center',
#                  color=text_color, fontsize=12)
#     label_color_mapping[label] = color
#
# # 添加坐标轴标签和标题
# plt.xlabel('Speed (fps)', fontsize=14)
# plt.ylabel('Accuracy (mIoU%)', fontsize=14)
# plt.title('Comparison of Accuracy and Speed', fontsize=16)
#
# # 添加图例，将图例放在右下角
# handles = [
#     plt.Line2D([0], [0], marker='.', color='w', markerfacecolor=label_color_mapping[label], markersize=10, label=label)
#     for label in model_names]
# plt.legend(handles=handles, loc='lower right')
#
# # 调整图像以更紧凑
# plt.margins(x=0.1, y=0.1)
#
# # 显示图表
# plt.grid(True)
# plt.show()

###########################################################################
# import matplotlib.pyplot as plt
#
# # 从文本文件读取数据
# with open("C:/Users/SONGSHITAO/Desktop/a.txt", "r") as file:
#     lines = file.readlines()
#
# # 提取网络名、精度和速度数据，使用空格分隔
# model_names = lines[0].strip().split()
# accuracies = [float(x) for x in lines[1].strip().split()]
# speeds = [float(x) for x in lines[2].strip().split()]
#
# # 创建散点图，增加图的尺寸
# plt.figure(figsize=(2,2))
#
# # 添加标签和颜色，同时记录标签和颜色的对应关系
# label_color_mapping = {}
# for i in range(len(model_names)):
#     label = model_names[i]
#
#     # 确保最后两个项目用不同颜色、相同形状
#     if i >= len(model_names) - 2:
#         color = 'r' if i == len(model_names) - 1 else 'b'
#         marker = 'o'
#     else:
#         color = plt.cm.jet(i / len(model_names))  # 使用颜色映射，确保每个顶点都有不同的颜色
#         marker = 'o'
#
#     plt.scatter(speeds[i], accuracies[i], c=color, marker=marker, s=100, label=label)
#     label_color_mapping[label] = (color, marker)
#
# # 添加垂直虚线以表示比较差的点
# plt.axvline(x=3, color='blue', linestyle='--')
#
# # 添加坐标轴标签和标题
# plt.xlabel('Speed (fps)', fontsize=14)
# plt.ylabel('Accuracy (mIoU%)', fontsize=14)
# plt.title('Comparison of Accuracy and Speed', fontsize=16)
#
# # 添加图例，将图例放在右下角
# handles = [plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=label_color_mapping[label][0], markersize=10,
#                       label=label) for label in model_names]
# plt.legend(handles=handles, loc='lower right')
#
# # 调整图像以更紧凑
# plt.margins(x=0.1, y=0.1)
#
# # 显示图表
# plt.grid(True)
# plt.show()
#


# #################################################################################################
# import matplotlib.pyplot as plt
#
# # 从文本文件读取数据
# with open("C:/Users/SONGSHITAO/Desktop/小论文/a.txt", "r") as file:
#     lines = file.readlines()
#
# # 提取网络名、精度和速度数据，使用空格分隔
# model_names = lines[0].strip().split()
# accuracies = [float(x) for x in lines[1].strip().split()]
# speeds = [float(x) for x in lines[2].strip().split()]
#
# # 创建散点图，增加图的尺寸
# plt.figure(figsize=(6, 6))
#
# # 添加标签和颜色，同时记录标签和颜色的对应关系
# label_color_mapping = {}
# colors = [ 'g',  'c', 'm', 'y', 'k', 'orange', 'purple', 'brown']  # 指定明亮的颜色
#
# for i in range(len(model_names)):
#     label = model_names[i]
#
#     # 确保最后两个项目用不同颜色、星形标记
#     if i >= len(model_names) - 2:
#         color = 'r' if i == len(model_names) - 1 else 'b'
#         marker = '*'
#     else:
#         color = colors[i % len(colors)]  # 使用预定义的颜色列表
#         marker = 'o'
#
#     plt.scatter(speeds[i], accuracies[i], c=color, marker=marker, s=100, label=label)
#     label_color_mapping[label] = (color, marker)
#
# # 添加垂直虚线以表示比较差的点
# plt.axvline(x=3.5, color='blue', linestyle='--')
#
# # 添加坐标轴标签和标题
# plt.xlabel('Speed (fps)', fontsize=14)
# plt.ylabel('Accuracy (mIoU%)', fontsize=14)
#
# # 添加图例，将图例放在右下角
# handles = [plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=label_color_mapping[label][0], markersize=15,
#                       label=label) for label in model_names]
# plt.legend(handles=handles, loc='lower right')
#
# # 调整图像以更紧凑
# plt.tight_layout()
#
# # 显示图表
# plt.grid(True)
# plt.show()



#############################################################################################
# import cv2
# import numpy as np
# import os
#
# # 设置输入和输出文件夹
# input_folder = "C:/Users/SONGSHITAO/Desktop/ca"  # 存放推理结果的文件夹
# gt_folder = "C:/Users/SONGSHITAO/Desktop/aeril_gt"
# output_folder = "C:/Users/SONGSHITAO/Desktop/d"  # 存放标注后的图像的文件夹
#
# # 获取输入文件夹中的所有文件
# input_images = os.listdir(input_folder)
#
# # 循环处理每个图像
# for image_filename in input_images:
#     # 读取推理结果和地面真实数据
#     inference_image = cv2.imread(os.path.join(input_folder, image_filename))
#     ground_truth_image = cv2.imread(os.path.join(gt_folder, image_filename))
#
#     # 提取目标类的像素
#     target_class = np.all(ground_truth_image == [255, 255, 255], axis=-1)
#
#     # 找到被错误分类的像素
#     misclassified_pixels = np.all(inference_image != ground_truth_image, axis=-1)
#
#     # 创建一个标注图像
#     annotation_image = np.copy(inference_image)
#
#     # 将被错误分类的目标标记为红色 (BGR格式)
#     annotation_image[misclassified_pixels & target_class] = [0, 0, 255]  # 红色
#
#     # 将被错误分类的背景标记为黄色
#     annotation_image[misclassified_pixels & ~target_class] = [154,250, 0]  # 黄色
#
#     # 保存标注后的图像到输出文件夹
#     output_path = os.path.join(output_folder, image_filename)
#     cv2.imwrite(output_path, annotation_image)









##############################################################################

#
# from PIL import Image
# import matplotlib.pyplot as plt
# import numpy as np
# import os
#
# # 指定包含PNG图像的文件夹路径
# directory_path = 'C:/Users/SONGSHITAO/Desktop/mask2/'
#
# # 遍历文件夹下的所有文件
# for filename in os.listdir(directory_path):
#     if filename.endswith('.png'):
#         image_path = os.path.join(directory_path, filename)
#
#         # 加载PNG图像
#         image = Image.open(image_path)
#
#         # 将图像转换为Numpy数组
#         image_array = np.array(image)
#
#         # 统计各个像素值的比例
#         unique, counts = np.unique(image_array, return_counts=True)
#         pixel_counts = dict(zip(unique, counts))
#
#         # 绘制柱状图
#         plt.bar(pixel_counts.keys(), pixel_counts.values())
#         plt.xlabel('Pixel Value')
#         plt.ylabel('Pixel Count')
#         plt.title(f'Pixel Value Distribution in {filename}')
#         plt.show()
##################################################################################

# from PIL import Image
# import matplotlib.pyplot as plt
# import numpy as np
# import os
#
# # 指定包含PNG图像的文件夹路径
# directory_path = 'C:/Users/SONGSHITAO/Desktop/aeril_gt/'
#
# # 初始化全局像素值计数器
# global_pixel_counts = {}
#
# # 获取文件夹下所有PNG图像的数量，用于计算百分比
# total_images = 0
#
# # 遍历文件夹下的所有文件
# for filename in os.listdir(directory_path):
#     if filename.endswith('.tif'):
#         total_images += 1
#         image_path = os.path.join(directory_path, filename)
#
#         # 加载PNG图像
#         image = Image.open(image_path)
#
#         # 将图像转换为Numpy数组
#         image_array = np.array(image)
#
#         # 统计各个像素值的比例并累积到全局计数器
#         unique, counts = np.unique(image_array, return_counts=True)
#         pixel_counts = dict(zip(unique, counts))
#
#         for key, value in pixel_counts.items():
#             global_pixel_counts[key] = global_pixel_counts.get(key, 0) + value
#
# # 计算各像素值的百分比
# for key in global_pixel_counts:
#     global_pixel_counts[key] /= (total_images * image_array.size)
#
# # 创建颜色映射以为每个柱着色
# colors = plt.cm.viridis(np.linspace(0, 1, len(global_pixel_counts)))
#
# # 绘制横向柱状图
# plt.barh(list(global_pixel_counts.keys()), list(global_pixel_counts.values()), color=colors)
# plt.ylabel('Pixel Value')
# plt.xlabel('Percentage')
# plt.title('Global Pixel Value Distribution (Percentage)')
# plt.show()



#
#
# import os
# import numpy as np
# import matplotlib.pyplot as plt
# import matplotlib.patches as mpatches  # 用于创建图例
# from PIL import Image
#
# # 遍历文件夹，读取掩膜
# folder_path = "C:/Users/SONGSHITAO/Desktop/mask2"  # 替换为掩膜所在文件夹的路径
# masks = [Image.open(os.path.join(folder_path, f)) for f in os.listdir(folder_path) if f.endswith('.png')]  # 假设掩膜为PNG格式
#
# # 统计像素
# pixel_counts = {}
# for mask in masks:
#     mask_array = np.array(mask)
#     unique, counts = np.unique(mask_array, return_counts=True)
#     for u, c in zip(unique, counts):
#         pixel_counts[u] = pixel_counts.get(u, 0) + c
#
# # 计算总像素数和每种像素的比重
# total_pixels = sum(pixel_counts.values())
# percentages = {k: v / total_pixels * 100 for k, v in pixel_counts.items()}
#
# # 绘制柱状图
#
#
#
# # 假设的像素值到标签的映射
# pixel_labels = {0: 'unknown', 1: 'urban', 2: 'agriculture', 3: 'rangeland',4: 'forest',5: 'water',6: 'barren'}  # 根据需要添加更多映射
#
# colors=['magenta', 'cyan', 'yellow', 'purple', 'green', 'blue', 'black']
# # 绘制柱状图
# labels, values = zip(*percentages.items())
# custom_labels = [pixel_labels.get(label, 'Unknown') for label in labels]  # 生成自定义标签列表
# bars = plt.bar(range(len(labels)), values, color=colors, width=0.6)  # 调整柱子的宽度
#
# # 创建图例
# legend_patches = [mpatches.Patch(color=colors[i], label=custom_labels[i]) for i in range(len(custom_labels))]
# plt.legend(handles=legend_patches, loc='upper right')  # 将图例放在图表外的空白处
#
# plt.ylabel('Percentage')
# plt.title('Deepglobe Dataset')
#
# # 隐藏x轴的原始标签
# plt.xticks([])
#
# # 显示百分比
# for i, bar in enumerate(bars):
#     plt.text(bar.get_x() + bar.get_width() / 2, bar.get_height() + 0.5, "{:.2f}%".format(values[i]), ha='center')
#
# plt.show()
#





# # 假设的像素值到标签的映射
# pixel_labels = {0: 'unknown', 1: 'urban', 2: 'agriculture', 3: 'rangeland',4: 'forest',5: 'water',6: 'barren'}  # 根据需要添加更多映射
#
# # 绘制柱状图
# labels, values = zip(*percentages.items())
# custom_labels = [pixel_labels[label] for label in labels]  # 生成自定义标签列表
# plt.bar(range(len(labels)), values, color=['black', 'cyan', 'yellow', 'purple', 'green', 'blue', 'black'])  # 颜色可调整
# plt.xticks(range(len(labels)), custom_labels)  # 使用自定义标签
# plt.ylabel('Percentage')
# plt.title('Deeoglobe Dataset')
#
# # 显示百分比
# for i, v in enumerate(values):
#     plt.text(i, v + 0.5, "{:.2f}%".format(v), ha='center')
#
# plt.show()

################################################################################################################
# import matplotlib.pyplot as plt
#
# # 从文本文件读取数据
# with open("C:/Users/SONGSHITAO/Desktop/小论文/a.txt", "r") as file:
#     lines = file.readlines()
#
# # 提取网络名、精度和速度数据，使用空格分隔
# model_names = lines[0].strip().split()
# accuracies = [float(x) for x in lines[1].strip().split()]
# speeds = [float(x) for x in lines[2].strip().split()]
#
# # 创建散点图，增加图的尺寸
# plt.figure(figsize=(6, 6))
#
# # 添加标签和颜色，同时记录标签和颜色的对应关系
# label_color_mapping = {}
#
#
# colors = ['g', 'c', 'm', 'y', 'k', 'orange', 'purple', 'brown',  'lime', 'pink']  # 自定义的颜色列表
#
#
# for i in range(len(model_names)):
#     label = model_names[i]
#
#     # 确保最后两个项目用不同颜色、星形标记
#     if i >= len(model_names) - 2:
#         color = 'r' if i == len(model_names) - 1 else 'b'
#         marker = '*'  # 将标记改为星号
#     else:
#         color = colors[i % len(colors)]  # 使用预定义的颜色列表
#         marker = 'o'
#
#     plt.scatter(speeds[i], accuracies[i], c=color, marker=marker, s=100, label=label)
#     label_color_mapping[label] = (color, marker)
#
# # 添加垂直虚线以表示比较差的点
# plt.axvline(x=3.5, color='blue', linestyle='--')
#
# # 添加坐标轴标签和标题
# plt.xlabel('Speed (fps)', fontsize=14)
# plt.ylabel('Accuracy (mIoU%)', fontsize=14)
#
# # 添加图例，将对应最后两个模型的标记都设为星号，并将图例放在右下角
# handles = [plt.Line2D([0], [0], marker='*', color='w', markerfacecolor=label_color_mapping[label][0], markersize=15,
#                       label=label) if label in model_names[-2:] else
#            plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=label_color_mapping[label][0], markersize=15,
#                       label=label) for label in model_names]
#
# plt.legend(handles=handles, loc='lower right')
#
# # 调整图像以更紧凑
# plt.tight_layout()
#
# # 显示图表
# plt.grid(True)
# plt.show()


